<?php

include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tucao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/album/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/app/inc.php");

//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival["p"], "p", "");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	if($g_cgival["p"] < 1) $g_cgival["p"]=1;
	
	cgi::both($g_cgival["id"], "id", "");
	$g_cgival["id"] = intval($g_cgival["id"]);
	
	cgi::both($g_cgival["pcount"], "pcount", 20);
	$g_cgival["pcount"] = intval($g_cgival["pcount"]);
	
	cgi::both($g_cgival["album_id"], "album_id", "");
	$g_cgival["album_id"] = intval($g_cgival["album_id"]);
	
	cgi::both($g_cgival["topic_id"], "topic_id", "");
	$g_cgival["topic_id"] = intval($g_cgival["topic_id"]);
	
	cgi::both($g_cgival["cid"], "cid", "");
	$g_cgival["cid"] = intval($g_cgival["cid"]);
	
	cgi::both($g_cgival["tokenString"], "tokenString", "");
	
	
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	
	$url="https://api.weibo.com/oauth2/authorize?client_id={$config["appkey"]}&response_type=token";
	
	echo $url;
	
	
	$tokenString = $g_cgival["tokenString"] ;
	
	$tokenString = base64_decode($tokenString);
	
	$tokenString= json_decode($tokenString,true);
	
	
	$uid = $g_cgival["cid"];
	
	$mod_mblog = new mod_mblog();
	$list = $mod_mblog->get_app_pubu_info(1,16,"",$uid);
	
	$g_show["list"] = $list["list"];
	$g_show["count"] = $list["count"];
	
	$Pages = new Pages($g_show["count"],$g_cgival["p"],$g_cgival["pcount"]);
	$g_show["page_bar"] = $Pages->getLinks("?topic_id={$g_cgival["topic_id"]}&show_type={$g_cgival["show_type"]}&order={$order}&p=",100);
	
	
	
	
	
	
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	
	$g_show["hide_shadow"] = true;
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	$smarty->display("app/index.html");
	
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

